/**
 * 将 Blob URL 转换为 Base64 字符串
 * @param blobUrl - 例如: 'blob:http://localhost:8082/...'
 * @returns Promise<string> - Base64 字符串
 */
export const blobUrlToBase64 = async (blobUrl: string): Promise<string> => {
    try {
        // 1. 获取 Blob 数据
        const response = await fetch(blobUrl);
        const blob = await response.blob();

        // 2. 转换为 Base64
        return await new Promise<string>((resolve, reject) => {
            const reader = new FileReader();
            reader.onloadend = () => {
                if (typeof reader.result === 'string') {
                    resolve(reader.result);
                } else {
                    reject(new Error('Failed to convert Blob to Base64.'));
                }
            };
            reader.onerror = () => reject(new Error('FileReader error.'));
            reader.readAsDataURL(blob);
        });
    } catch (error) {
        console.error('Error converting Blob URL to Base64:', error);
        throw error;
    }
};